import java.util.ArrayDeque;
import java.util.Deque;

/**
 * @program: LeetCode
 * @description: LeetCode :
 * @author: WXY
 * @create: 2023-01-16 09:46
 * @Version 1.0
 **/
public class Num225_MyStack {
    class MyStack {
        Deque<Integer> deque1;
        Deque<Integer> deque2;
        public MyStack() {
            deque1 = new ArrayDeque<>();
            deque2 = new ArrayDeque<>();
        }

        public void push(int x) {
            deque1.addLast(x);
        }

        public int pop() {
            int size = deque1.size();
            while (size > 1) {
                deque2.push(deque1.pop());
                size--;
            }
            int ans = deque1.pop();
            deque1 = deque2;
            deque2 = new ArrayDeque<>();
            return ans;
        }

        public int top() {
            return deque1.peekLast();
        }

        public boolean empty() {
            return deque1.isEmpty();
        }
    }
}
